#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int t, n, m;



int main() {
    cin >> t;
    while(t--) {
        string a, b, c;
        cin >> a >> c;
        bool flag = 1;
        int l1 = a.size(), l2 = c.size();

        int i = l1-1, j = l2-1;
        while(i>=0 || j>=0) {
            if (i>=0 && j<0) {
                flag = 0;
                break;
            }

            if (i<0 && j>=0) {
                b.push_back(c[j]);
                j--;
                continue;
            }

            if (c[j] - a[i] < 0) {
                if (c[j-1] != '1') {
                    flag = 0;
                    break;

                } else {
                    int num = 10 + (c[j] - '0');
                    int temp = num - (a[i] - '0');

                    char x = temp + '0';
                    b.push_back(x);
                    j--;
                }
            } else {
                int num = c[j]-a[i];
                char x = num + '0';
                b.push_back(x);
            }
            i--,j--;
        }

        for (int i = b.size() - 1; i >= 0; i--) {
            if (b[i] == '0') b.pop_back();
            else break;
        }

        if (!flag) {
            cout << -1 << endl;
            continue;
        }

        reverse(b.begin(), b.end());
        cout << b << endl;
    }
    return 0;

    return 0;
}